package com.flw.eslab.service.impl;

import java.io.File;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.flw.eslab.dao.ProjectDao;
import com.flw.eslab.dto.PageInfo_Dto;
import com.flw.eslab.model.Info;
import com.flw.eslab.model.Project;
import com.flw.eslab.service.ProjectManager;


@Service("projectManager")
public class ProjectManagerImpl implements ProjectManager {
	@Resource
	private ProjectDao projectDao;
	public ProjectDao getProjectDao() {
		return projectDao;
	}
	public void setProjectDao(ProjectDao projectDao) {
		this.projectDao = projectDao;
	}



	@Override
	public boolean delete(Project project) {
		if(project.getId()==null){
			project.setId(0);
		}
		if(projectDao.findById(Project.class, project.getId())==null){
			return false;
		}else{
			projectDao.deleteById(Project.class, project);
			return true;
		}
	}

	@Override
	public boolean modify(Project project) {
		if(project.getId()==null){
			project.setId(0);
		}
		if(projectDao.findById(Project.class, project.getId())==null||project.getName()==null||project.getName().equals("")){
			return false;
		}else{
			projectDao.update(project);
			return true;
		}
	}

	@Override
	public File output() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public PageInfo_Dto load(PageInfo_Dto pageInfo_Dto) {
		int pageNow=pageInfo_Dto.getPageNow()==null?1:pageInfo_Dto.getPageNow();
		int pageSize=pageInfo_Dto.getPagesize()==null?5:pageInfo_Dto.getPagesize();	
		return projectDao.findByPageInfo(Project.class, pageNow, pageSize, null, null);
	}
	@Override
	public boolean add(Project project) {
		// TODO Auto-generated method stub
		if(project.getName()==null||project.getName().equals(""))
			return false;
		else{
			projectDao.save(project);
			return true;
		}
	}
}
